let db = require('../db.js');

//获取用户详情信息

exports.getUserDetail = async function (userId) {
    let sql=`
     SELECT userName,password,email,phone,role, avatar FROM admin   where id =:userId
    `
    let data  = await db.query(sql,{userId});
    return data[0][0];
}

//验证用户名昵称是否重复
exports.valicationUserName  = async function(userId,userName){
    let sql=`
    SELECT *  FROM  admin  where userName=:userName  AND id !=:userId 
    
    `
    let  data  = await db.query(sql,{userId,userName});
    return data[0];
}

//修改用户基本信息
exports.updateUserBasic  = async function(userId,userName,phone,email){
  let sql=`
   UPDATE admin SET  
   userName=:userName,
   phone =:phone,
   email =:email
   where id =:userId

  `
  let data = await db.query(sql,{userId,userName,phone,email});
  return data[0];

}

//修改用户头像
exports.updateUserAvatar = async function(userId,avatar){
let sql=`
UPDATE admin SET  
avatar=:avatar
where id =:userId
`
let  data = await db.query(sql,{userId,avatar});
return data[0];
}

//修改用户密码
exports.updatePwd =  async function(userId,newPass){
    let sql=`
    UPDATE admin SET  
    password=:newPass
    where id =:userId
    `
    let  data = await db.query(sql,{userId,newPass});
    return data[0];  
}